<template>
  <el-container>
    <el-aside :width="isCollapse?'64px':'200px'">
      <div class="logo" @click="toggleCollapse">
        <img :width="isCollapse?'35px':'61px'" src="../assets/heima.png" />
        <p class="systemName">{{systemName}}</p>
      </div>
      <el-menu
        background-color="#242424"
        text-color="#fff"
        active-text-color="#4291ca"
        unique-opened
        :collapse="isCollapse"
        :collapse-transition="false"
        router
        :default-active="highLightPath"
      >
        <el-submenu :index="item.id+''" v-for="item in menulist" :key="item.id">
          <template slot="title">
            <i :class="icons[item.id]"></i>
            <span>{{item.authName}}</span>
          </template>
          <el-menu-item
            :index="'/'+subItem.path"
            v-for="subItem in item.children"
            :key="subItem.id"
            @click="highLight('/'+subItem.path)"
          >
            <i class="el-icon-box"></i>
            <span>{{subItem.authName}}</span>
          </el-menu-item>
        </el-submenu>

        <el-menu-item index="4" @click="logout">
          <i class="el-icon-back"></i>
          <span>退出</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    <el-container>
      <!-- <el-header>
        Header
      </el-header>-->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      systemName: "蓝马后台管理系统",
      aaa:'123',
      menulist: {},
      icons: {
        "125": "el-icon-user-solid",
        "103": "el-icon-s-platform",
        "101": "el-icon-s-goods",
        "102": "el-icon-s-order",
        "145": "el-icon-s-marketing"
      },
      isCollapse: false,
      highLightPath: ""
    };
  },

  created() {
    this.getMenulist();
    this.highLightPath = window.sessionStorage.getItem("activePath");
  },

  methods: {
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    async getMenulist() {
      const { data: res } = await this.$http.get("menus");
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg);
      this.menulist = res.data;
    },
    toggleCollapse() {
      this.isCollapse = !this.isCollapse;
      this.systemName = this.isCollapse ? "蓝马" : "蓝马后台管理系统";
      console.log(this.menulist);
    },
    highLight(activePath) {
      window.sessionStorage.setItem("activePath", activePath);
      this.highLightPath = activePath;
    }
  }
};
</script>

<style scoped lang='less'>
.el-header {
  background-color: #fff;
}
.el-aside {
  background-color: #242424;
  .el-menu {
    border-right: 0;
  }
}
.el-main {
  background-color: #e9edf1;
}
.el-container {
  height: 100%;
}
.logo {
  height: 150px;
  background-color: #4291ca;
  text-align: center;
  padding-top: 45px;
  .systemName {
    color: #fff;
  }
}
</style>
